package org.daidai.abstrusewriting.homepage.hot.client;



import android.util.Log;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

/**
 * Created by Administrator on 2016/10/31.
 */

public class OkHttpUtilImp {
    private OkHttpClient okHttpClient;
    public OkHttpUtilImp(){
        okHttpClient = new OkHttpClient();
    }
    public void doGetDataSync(String url, final HttpCallBack callBack){
        if (url!=null) {
            Request.Builder builder = new Request.Builder();
            Request request = builder.url(url).get().build();
            okHttpClient.newCall(request).enqueue(new Callback() {
                @Override
                public void onFailure(Call call, IOException e) {

                }
                @Override
                public void onResponse(Call call, Response response) throws IOException {
                    int code = response.code();
                    if (code==200) {
                        byte[] bytes = response.body().bytes();

                        if (callBack!=null) {
                            callBack.onSuccess(code,bytes);
                        }

                    }
                }
            });

    }
}
}